package co.gov.medellin.ssti.sub.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;

import javax.naming.NamingException;

import co.gov.medellin.ssti.sub.common.ConexionFactory;
import co.gov.medellin.ssti.sub.model.dao.DAOFactory;
import co.gov.medellin.ssti.sub.model.dao.IRepDetCruceDAO;
import co.gov.medellin.ssti.sub.model.dao.exception.DAOException;
import co.gov.medellin.ssti.sub.model.vo.BeneficiarioVO;
import co.gov.medellin.ssti.sub.model.vo.RepDetCruceVO;

public class RepDetCruceService {
	/**
	 * 
	 * @param criteria
	 * @return
	 * @throws SQLException
	 */
	public Collection<BeneficiarioVO> findBeneficiariosCruce(
			RepDetCruceVO criteria) throws DAOException {
		IRepDetCruceDAO repDetCruceDAO = null;
		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			repDetCruceDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getRepDetCruceDAO(con);
			return repDetCruceDAO.findBeneficiariosCruce(criteria);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (repDetCruceDAO != null) {
				if (!repDetCruceDAO.isConnClosed()) {
					repDetCruceDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param criteria
	 * @return
	 * @throws DAOException
	 */
	public Long findCantidadBeneficiarios(RepDetCruceVO criteria)
			throws DAOException {
		IRepDetCruceDAO repDetCruceDAO = null;
		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			repDetCruceDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getRepDetCruceDAO(con);
			return repDetCruceDAO.findCantidadBeneficiarios(criteria);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (repDetCruceDAO != null) {
				if (!repDetCruceDAO.isConnClosed()) {
					repDetCruceDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param repDetCruceVO
	 * @return
	 * @throws SQLException
	 */
	public RepDetCruceVO findFilters(RepDetCruceVO repDetCruceVO)
			throws DAOException {
		IRepDetCruceDAO repDetCruceDAO = null;
		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			repDetCruceDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getRepDetCruceDAO(con);
			return repDetCruceDAO.findFilters(repDetCruceVO);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (repDetCruceDAO != null) {
				if (!repDetCruceDAO.isConnClosed()) {
					repDetCruceDAO.close();
				}
			}
		}
	}
}
